package cn.dw.utils;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class ConditionType {
	public static final String OPER_EQ = " = ";
	public static final String OPER_LE = " <= ";
	public static final String OPER_GE = " >= ";
	public static final String OPER_LIKE = " LIKE ";
	public static final String OPER_NULL = " IS NULL ";
	public static final String OPER_NONULL = " IS NOT NULL ";
	public static final String OPER_GT = " > ";
	public static final String OPER_LT = " < ";
	public static final String OPER_NE = " != ";
	public static final String OPER_EQProperty = " = ";
	public static final String OPER_LEProperty = " <= ";
	public static final String OPER_GEProperty = " >= ";
	public static final String OPER_GTProperty = " > ";
	public static final String OPER_LTProperty = " < ";
	public static final String OPER_NEProperty = " != ";
	public static final int IOPER_EQ = 0;
	public static final int IOPER_LE = 1;
	public static final int IOPER_GE = 2;
	public static final int IOPER_LIKE = 3;
	public static final int IOPER_NULL = 4;
	public static final int IOPER_NONULL = 5;
	public static final int IOPER_GT = 6;
	public static final int IOPER_LT = 7;
	public static final int IOPER_NE = 8;
	public static final int IOPER_IN = 9;
	public static final int IOPER_EQProperty = 10;
	public static final int IOPER_LEProperty = 11;
	public static final int IOPER_GEProperty = 12;
	public static final int IOPER_GTProperty = 13;
	public static final int IOPER_LTProperty = 14;
	public static final int IOPER_NEProperty = 15;
	public static final int DATA_STRING = 1;
	public static final int DATA_NUMBER = 2;
	public static final int DATA_DATE = 3;
	public static final int LINK_AND = 11;
	public static final int LINK_OR = 12;
	private String name;
	private String otherName;
	private Object value;
	private Object[] values;
	private String operator;
	private int ioperator;
	private Integer dataType;
	private int linkType;
	List<ConditionType> conditionTypes = null;

	public ConditionType() {
	}

	public ConditionType(String name, String otherName, String operator) {
		this.name = name;
		this.otherName = otherName;
		this.operator = operator;
	}

	public ConditionType(String name, String otherName, int ioperator) {
		this.name = name;
		this.otherName = otherName;
		this.ioperator = ioperator;
	}

	public ConditionType(String name, Object value, String operator) {
		this.name = name;
		this.value = value;
		this.operator = operator;
	}

	public ConditionType(String name, Object value, int ioperator) {
		this.name = name;
		this.value = value;
		this.ioperator = ioperator;
	}

	public ConditionType(String name, Object[] values, String operator) {
		this.name = name;
		this.values = values;
		this.operator = operator;
	}

	public ConditionType(String name, Object[] values, int ioperator) {
		this.name = name;
		this.values = values;
		this.ioperator = ioperator;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOtherName() {
		return this.otherName;
	}

	public void setOtherName(String otherName) {
		this.otherName = otherName;
	}

	public Object getValue() {
		return this.value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public Object[] getValues() {
		return this.values;
	}

	public void setValues(Object[] values) {
		this.values = values;
	}

	public String getOperator() {
		return this.operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public int getIoperator() {
		return this.ioperator;
	}

	public void setIoperator(int ioperator) {
		this.ioperator = ioperator;
	}

	public Integer getDataType() {
		return this.dataType;
	}

	public void setDataType(Integer dataType) {
		this.dataType = dataType;
	}

	public int getLinkType() {
		return this.linkType;
	}

	public void setLinkType(int linkType) {
		this.linkType = linkType;
	}

	public List<ConditionType> getConditionTypes() {
		return this.conditionTypes;
	}

	public void setConditionTypes(List<ConditionType> conditionTypes) {
		this.conditionTypes = conditionTypes;
	}

	public static ConditionType eq(String name, Object value) {
		return new ConditionType(name, value, 0);
	}

	public static ConditionType le(String name, Object value) {
		return new ConditionType(name, value, 1);
	}

	public static ConditionType ge(String name, Object value) {
		return new ConditionType(name, value, 2);
	}

	public static ConditionType like(String name, Object value) {
		return new ConditionType(name, value, 3);
	}

	public static ConditionType isNull(String name, Integer dataType) {
		return new ConditionType(name, "", 4);
	}

	public static ConditionType noNull(String name, Integer dataType) {
		return new ConditionType(name, "", 5);
	}

	public static ConditionType gt(String name, Object value) {
		return new ConditionType(name, value, 6);
	}

	public static ConditionType lt(String name, Object value) {
		return new ConditionType(name, value, 7);
	}

	public static ConditionType ne(String name, Object value) {
		return new ConditionType(name, value, 8);
	}

	public static ConditionType in(String name, Object[] values) {
		return new ConditionType(name, values, 9);
	}

	public static ConditionType or(ConditionType... conditionTypes) {
		ConditionType ct = new ConditionType();
		ct.setLinkType(12);
		List<ConditionType> cts = new LinkedList<>();

		ConditionType[] arrayOfConditionType = conditionTypes;
		int j = conditionTypes.length;
		for (int i = 0; i < j; i++) {
			ConditionType c = arrayOfConditionType[i];
			cts.add(c);
		}
		ct.setConditionTypes(cts);
		return ct;
	}

	public static ConditionType EQProperty(String name, String otherName) {
		return new ConditionType(name, otherName, 10);
	}

	public static ConditionType LEProperty(String name, String otherName) {
		return new ConditionType(name, otherName, 11);
	}

	public static ConditionType GEProperty(String name, String otherName) {
		return new ConditionType(name, otherName, 12);
	}

	public static ConditionType GTProperty(String name, String otherName) {
		return new ConditionType(name, otherName, 13);
	}

	public static ConditionType LTProperty(String name, String otherName) {
		return new ConditionType(name, otherName, 14);
	}

	public static ConditionType NEProperty(String name, String otherName) {
		return new ConditionType(name, otherName, 15);
	}

	public String toString() {
		return

		"ConditionType [name=" + this.name + ", otherName=" + this.otherName + ", value=" + this.value + ", values="
				+ Arrays.toString(this.values) + ", operator=" + this.operator + ", ioperator=" + this.ioperator
				+ ", dataType=" + this.dataType + ", linkType=" + this.linkType + "]";
	}
}
